//
//  HomeViewModel.m
//  AppointmentForCar
//
//  Created by TheMacBook on 2016/11/15.
//  Copyright © 2016年 Herron. All rights reserved.
//

#import "HomeViewModel.h"
#import "RideHailingModel.h"
@implementation HomeViewModel
- (void)homeCallCarWithOrigin:(NSString *)origin destination:(NSString *)destination complete:(homeEventBackCall)block
{
    UserModel * user = [UserAccountManager shareUserManager].user;
    NSDictionary * params = @{@"id":user.userId,@"nickName":user.nickName,@"phoneNumber":user.phoneNumber,@"origin":origin,@"destination":destination,@"time":[NSString nowDate]};
    [NetWork postNetWorkWithUrl:@"ride-hailing" parame:params successBlock:^(NSDictionary *dic) {
        if([dic[@"status"] integerValue] != 0)
        {
            block(dic[@"message"]);
        }else
        {
            _rideHailing = [RideHailingModel mj_objectWithKeyValues:dic[@"data"][@"data"]];
            self.isCall = YES;
            block(nil);
        }
    } errorBlock:^(id error) {
        block(error);
    }];
}
- (void)homeCancelCallCarWithComplete:(homeEventBackCall)block
{
    [NetWork postNetWorkWithUrl:@"cancel-ride-hailing" parame:@{@"id":_rideHailing.passengerId,@"reservationId":_rideHailing.orderId} successBlock:^(NSDictionary *dic) {
        if([dic[@"status"] integerValue] != 0)
        {
            block(dic[@"message"]);
        }else
        {
            block(nil);
            self.isCall = NO;
        }
    } errorBlock:^(id error) {
        block(error);
    }];
}
- (void)setIsCall:(BOOL)isCall
{
    _isCall = isCall;
    [PushManager sharePushManager].pushSwith = isCall;
}
@end
